package lesson19;

import java.util.Scanner;

public class SecuredNotepade extends SimpleNotepade implements ISecuredNotepade{
	private String pasword;
	Scanner sc = new Scanner(System.in);
	SecuredNotepade(int pagesNumber,String pasword) {
		super(pagesNumber);		
		if(pasword.equals("")){		
			do {
				System.out.println("Enter correct password");
				pasword = sc.next();
			} while (!pasword.equals(""));
		}
		this.pasword=pasword;
		
	}
	@Override
	public void addText(int pageNumber, String text) {		
		if(enterPassword()){
			super.addText(pageNumber, text);
		}else
			System.out.println("Wrong password!");
	}
	@Override
	public void replace(int pageNumber, String text) {		
		if(enterPassword()){
			super.replace(pageNumber, text);
		}else
			System.out.println("Wrong password!");
	}
	@Override
	public void deleteText(Page selectedPage) {
		if(enterPassword()){
			super.deleteText(selectedPage);
		}else
			System.out.println("Wrong password");
		
	}
	@Override
	public void printPages() {
		if(enterPassword())
			super.printPages();
	}
	public boolean enterPassword(){
		System.out.println("Enter password!");
		String pasword = sc.next();
		
		return this.pasword.equals(pasword);
		
	}
	
	

}
